package com.rw.coco.handler.message.reply.handler.normal;

import com.rw.coco.handler.message.event.CocoMessageEvent;
import com.rw.coco.handler.message.reply.ReplyHandler;
import com.rw.coco.util.config.CocoConfig;
import com.rw.coco.util.config.CocoOption;

/**
 * 呼叫可可，给予的回复
 */
public class CocoHandler implements ReplyHandler {
    public final boolean funcSwitch;

    public CocoHandler(CocoConfig cocoConfig) {
        CocoOption cocoOption = cocoConfig.getCocoOption();
        this.funcSwitch = cocoOption.optionProp.getBoolean(CocoOption.COCO_CALL);
    }

    @Override
    public boolean trigger(CocoMessageEvent cocoMessageEvent) {
        String botName = cocoMessageEvent.getReplyApi().getEntertainingReply().getBotName();
        String message = cocoMessageEvent.getMessage();

        return funcSwitch && message.startsWith(botName) && message.length() <= botName.length() + 1;
    }

    @Override
    public void handler(CocoMessageEvent cocoMessageEvent) {
        String reply = cocoMessageEvent.getReplyApi().getEntertainingReply().callTheBotName(cocoMessageEvent);
        cocoMessageEvent.sendBack(reply);
    }

    @Override
    public int priority() {
        return 0;
    }
}
